import React from 'react'
import { Layout, Card, Modal, Space, Table, Tabs } from 'antd';

import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import {
    PieChartOutlined,
    DownloadOutlined
} from '@ant-design/icons';

import axios from 'axios';
const { TabPane } = Tabs;


// const data = [
//     {
//         key: 0,
//         num: 1,
//     },
//     {
//         key: 1,
//         num: 2,
//     },
//     {
//         key: 2,
//         num: 3,
//     }
// ];




const { Header, Sider } = Layout;
export default class Content extends React.Component {
    constructor(props) {
        super(props);
        this.LinkToAnswer = this.LinkToAnswer.bind(this);
        this.LinkToList = this.LinkToList.bind(this);
        this.state = {
            q_id: 58,
            title: '',
            data: [],
        }
    }
    componentWillMount() {
        let _this = this;
        // let value = _this.props.location.state;
        // this.setState({
        //     q_id: value,
        // })
        // console.log(value);
        axios.post('/getUid', { q_id: 58 })
            .then(res => {
                let list = res.data.data.uid_list;
                console.log(list);
                list.map((item, i, array) => {
                    const newData = {
                        key: i,
                        num: item
                    }
                    this.setState((prevState) => ({
                        data: prevState.data.concat(newData),
                    }));
                })

            })

    }

LinkToAnswer(key) {
    // let value = this.state.q_id;
    let path = {
        pathname: '/check',
        state: 58,
        uid: key
    };
    this.props.history.push(path);
}
LinkToList() {
    let path = {
        pathname: '/content',
        state: this.state.q_id,
    };
    console.log(path);
        this.props.history.push(path);
}

    render() {
        const columns = [
            {
                title: '序号',
                dataIndex: 'num',
                key: 'num',
            },
            {
                title: '查看答卷',
                key: 'action',
                render: (text, record) => (
                    <Space size="middle" >
                        <a onClick={()=>this.LinkToAnswer(record.num)}>查看答卷</a>
                    </Space>
                )
            },
        ];
        return (
            <Layout className="main">
                <Header className="head" style={{ position: 'fixed', zIndex: 1, width: '100%' }}>
                    <div className="logo" />
                    <Link to="/home">
                    <span className="leftest">返回</span></Link>
                    <div className="left" onClick={this.LinkToList}><PieChartOutlined style={{ marginRight: 5 }} />统计&分析</div>
                        <span className="right" ><DownloadOutlined style={{ marginRight: 5 }} />查看下载答卷</span>
                </Header>
                <Layout className="site-layout" style={{ marginTop: 70 }}>
                    <Table
                    style={{textAlign:'center'}}
                        columns={columns}
                        dataSource={this.state.data}
                    />
                </Layout>
            </Layout>
        )
    }

}